//
//  HWOnlineGameQCViewController.m
//  94hwanGame
//
//  Created by Chendaobin on 2019/8/21.
//  Copyright © 2019年 王治庭. All rights reserved.
//

#import "HWOnlineGameQCViewController.h"
#import "HWOnlinegameTableCell.h"
#import "SDCycleScrollViewCdb.h"
#import "HWMobileGameView.h"
#import "HWAdvertisingQCTableViewCell.h"
#import "AdModel.h"
#import "HWNewsModel.h"
#import "HRAdView.h"
#import "HWJingPingModel.h"
#import "HWGameListModel.h"
#import "HWIcon3TableviewCell.h"
#import "HWRenqiOrZuixinOrYuGaoView.h"
#import "HWYouXiCell.h"
#import "FenLeiViewController.h"

#import "HWWebViewGameViewController.h"


@interface HWOnlineGameQCViewController ()<UITableViewDelegate,UITableViewDataSource,SDCycleScrollViewCdbDelegate>
@property(strong,nonatomic) UITableView *mainaTableVie;
@property(strong,nonatomic) UIView *headerView; //tabbarView
@property(strong,nonatomic) SDCycleScrollViewCdb *cycleScrollView;
@property(strong,nonatomic) UIView *shufflingFigureView; // 轮播图  + 提示器的Uiview
@property(strong,nonatomic) UILabel *rollingLabel; //滚动
@property(strong,nonatomic) UIView *qualitygameView;

@property(strong,nonatomic)
HWMobileGameView *mobileGameView;
@property(strong,nonatomic)HRAdView *adgugaview;
@property(strong,nonatomic)UIButton  *xuanzhongBut; // 存储选中Button
@property (strong,nonatomic) NSMutableArray *ADModelMuArr;
@property(strong,nonatomic) NSMutableArray *xingweMuArr; // 新闻
@property(strong,nonatomic) NSMutableArray *jingpinMuArr; // 精品网游

@property(strong,nonatomic) NSMutableArray *sentimentMuArr; // 人气热门
@property(strong,nonatomic) NSMutableArray *latestMutaBleArr; // 最新上架
@property(strong,nonatomic) NSMutableArray *trailerMutableArr; // 预告
@property(assign,nonatomic) CGFloat diyigeheight; // 人气热门 高的
@property(assign,nonatomic) CGFloat ergeheight;
@property(assign,nonatomic) CGFloat sangegeheight;
@property(strong,nonatomic) UIView *addFootView;
@property(strong,nonatomic) HWRenqiOrZuixinOrYuGaoView *renqiOrZuixinview; // 包含
@property(assign,nonatomic) int xuanzhongTag;

@property(strong,nonatomic) NSString *reQiP;
@property(strong,nonatomic) NSString *reQiMax_p;

@property(strong,nonatomic) NSString *zuixinP;
@property(strong,nonatomic) NSString *zuixinMax_p;

@property(strong,nonatomic) NSString *yugaoP;
@property(strong,nonatomic) NSString *yugaoMax_p;



@end

@implementation HWOnlineGameQCViewController


- (SDCycleScrollViewCdb *)cycleScrollView {
    if (!_cycleScrollView) {
        // 网络加载 --- 创建不带标题的图片轮播器
        _cycleScrollView = [SDCycleScrollViewCdb cycleScrollViewWithFrame:CGRectMake(10, 0, kScreenW-2*10, 120) imageURLStringsGroup:nil];

        _cycleScrollView.infiniteLoop = YES;
        _cycleScrollView.delegate = self;
       // _cycleScrollView.placeholderImage=[UIImage imageNamed:@"banner"];
        _cycleScrollView.pageControlStyle = SDCycleScrollViewCdbPageContolStyleClassic;
        _cycleScrollView.autoScrollTimeInterval = 2.0; // 轮播时间间隔，默认1.0秒，可自定义
        
         _cycleScrollView.backgroundColor = [UIColor clearColor];
    }
    return _cycleScrollView;
}


-(UITableView *)mainaTableVie {

    if (_mainaTableVie == nil
        ) {


        _mainaTableVie = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, kScreenH-CF_NavHeight-44-CF_TabbarHeight) style:UITableViewStylePlain];
        _mainaTableVie.delegate = self;
        _mainaTableVie.dataSource = self;
        _mainaTableVie.separatorStyle = UITableViewCellSeparatorStyleNone;
        _mainaTableVie.backgroundColor = [UIColor whiteColor];


    }
    return   _mainaTableVie ;
}



- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.


    // 设置属性
    [self setupAttribute];
    // 添加控件
    [self setupUI];

    //添加Tabaview 头部
    [self setupheadeView];

    [self addtablviefootView];
    
    // 添加刷新控件
    [self addrefreshControl];
    


    //发送网路请求
  //  [self networkRequestData];

    // 监听通知
    [self listeningNSNotificationCenter];
    
    
    
    
    
    





}


#pragma  mark ---- 添加刷新

- (void)addrefreshControl {
    
    self.mainaTableVie.mj_header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(underRefresh)];
    
    [self.mainaTableVie.mj_header beginRefreshing];
    
    self.mainaTableVie.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(onRefresh)];
}


#pragma  mark --------- 下拉刷新
- (void)underRefresh {
    
//    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
//        // 结束刷新
//        [self.mainaTableVie.mj_header endRefreshing];
//    });
    
    
   // [SVProgressHUD show];
    __weak typeof(self) weakSelf = self;
  
    
//    NSDictionary *parametes = @{
//                                @"type" : @"0",
//                                @"t" : @"0",
//                                @"ct" :  @"app",
//                                @"ac" : @"index"
//
//                                };
    
    
    
    NSDictionary *parametes = @{
                        @"type" : @"0",
                         @"t" : @"0",
                         @"ios" : @"1",
                         @"ct" :  @"app",
                         @"ac" : @"index"
                                };

    [HWWebUtils doGetWithParameters:parametes progress:nil success:^(id response) {
        
       // [SVProgressHUD dismiss];
         [self.mainaTableVie.mj_header endRefreshing];
         [self.mainaTableVie.mj_footer endRefreshing];
        
        
        NSString *codeStr =  [NSString stringWithFormat:@"%@",response[@"code"]];
        
        if ([codeStr intValue] == 1) {
            
            NSArray *arr  = response[@"banner"];
            
            NSMutableArray *icoArr = [[NSMutableArray alloc]init];
                        
                    for (int i = 0 ; i < arr.count; i ++) {
                       NSMutableDictionary   *dic = [arr[i] mutableCopy];
                                
                       NSString *imagestr  = [NSString stringWithFormat:@"%@", dic[@"image"]];
                                    
                       if ([imagestr containsString:@"http"] || [imagestr containsString:@"https"] ) {
                                        
                      } else {
                                        NSString *image = [NSString stringWithFormat:@"http:%@", dic[@"image"]];
                                        [dic setValue:image forKey:@"image"];
                                        
                      }

                      [icoArr addObject:dic];
                                    
                            

                   }
                            
                  self.ADModelMuArr =  [AdModel mj_objectArrayWithKeyValuesArray:icoArr];
            
            
          //  self.ADModelMuArr =  [AdModel mj_objectArrayWithKeyValuesArray:arr];
            
            NSArray *newsArr  = response[@"news"];
            
            self.xingweMuArr = [HWNewsModel mj_objectArrayWithKeyValuesArray:newsArr];
            
            NSArray *jingpinArr  = response[@"jingpin"];
            self.jingpinMuArr =  [HWJingPingModel mj_objectArrayWithKeyValuesArray:jingpinArr];
            
            
            NSArray *renqiArr  = response[@"data"][0][@"list"];
            self.sentimentMuArr = [HWGameListModel mj_objectArrayWithKeyValuesArray:renqiArr];
            
            self.reQiP = response[@"data"][0][@"p"];
            self.reQiMax_p = response[@"data"][0][@"max_p"];
            
            
            NSArray *latestArr  = response[@"data"][1][@"list"];
            self.latestMutaBleArr  = [HWGameListModel mj_objectArrayWithKeyValuesArray:latestArr];
            
            self.zuixinP = response[@"data"][1][@"p"];
            self.zuixinMax_p = response[@"data"][1][@"max_p"];
            
            NSArray *traileArr = response[@"data"][2][@"list"];
            self.trailerMutableArr  = [HWGameListModel mj_objectArrayWithKeyValuesArray:traileArr];
            
            self.yugaoP = response[@"data"][2][@"p"];
            self.yugaoMax_p = response[@"data"][2][@"max_p"];
            
            // 算出这个这三个数据的高度
            [self yixeilingshi];
            [self zuixingshangjian];
            [self youxiyugao];
            [self refreshData];
        }
        NSLog(@"%@",response);
        
        
    } failure:^(NSString *error) {
        [self.mainaTableVie.mj_header endRefreshing];
        [self.mainaTableVie.mj_footer endRefreshing];
        
        
    }];

    
    
}

#pragma  mark ---------- 上拉刷新
- (void)onRefresh {
    
    
//    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
//        // 结束刷新
//        [self.mainaTableVie.mj_footer endRefreshing];
//    });
    
    NSString *t = nil;
    NSString *p = nil;
//    if(self.xuanzhongTag == 0) {
//        t = @"0";
//        p = self.reQiP;
//        
//        
//    } else if (self.xuanzhongTag == 1) {
//        
//        t = @"1";
//        p = self.zuixinP;
//        
//        
//        
//        
//    } else {
//        
//        t = @"2";
//        p = self.yugaoP;
//        
//    }
    
    
    if(self.xuanzhongTag == 0) {
           t = @"0";
           p = self.reQiP;
           
           
           if ([self.reQiP intValue] > [self.reQiMax_p intValue] ) {
               
               [self.mainaTableVie.mj_header endRefreshing];
               [self.mainaTableVie.mj_footer endRefreshing];
               return;
               
           }
           
           
       } else if (self.xuanzhongTag == 1) {
           
           t = @"1";
           p = self.zuixinP;
           
           
           if ([self.zuixinP intValue] > [self.zuixinMax_p intValue] ) {
                      
                    
               [self.mainaTableVie.mj_header endRefreshing];
               [self.mainaTableVie.mj_footer endRefreshing];
                      return;
                      
           }
           
           
           
           
       } else {
           
           
         
           
           t = @"2";
           p = self.yugaoP;
           
           
           if ([self.yugaoP intValue] > [self.yugaoMax_p intValue] ) {
                                 
               [self.mainaTableVie.mj_header endRefreshing];
               [self.mainaTableVie.mj_footer endRefreshing];
               return;
                                 
           }
           
       }
    
    
    
    __weak typeof(self) weakSelf = self;
//    NSDictionary *parametes = @{
//                                @"type" : @"0",
//                                @"t" : t,
//                                @"p" : p,
//                                @"ct" :  @"app",
//                                @"ac" : @"index"
//                                
//                                };
    NSDictionary *parametes = @{
                                @"type" : @"0",
                                @"t" : t,
                                @"p" : p,
                                @"ios" : @"1",
                                @"ct" :  @"app",
                                @"ac" : @"index"

                                };
    
    NSLog(@"数据的显示： %@",parametes);

    
    [HWWebUtils doGetWithParameters:parametes progress:nil success:^(id response) {
        
        // [SVProgressHUD dismiss];
        [self.mainaTableVie.mj_header endRefreshing];
        [self.mainaTableVie.mj_footer endRefreshing];
        
    
        NSString *codeStr =  [NSString stringWithFormat:@"%@",response[@"code"]];
        
        if ([codeStr intValue] == 1) {
            
            NSLog(@"%@",response[@"data"][0][@"list"]);
            
            
            if ([response[@"data"][0][@"list"] isKindOfClass:[NSString class]]) {

                [MBProgressHUD showtext:@"暂无数据" icon:nil view:nil];
                return;

            }
            
            if ([response[@"data"][0][@"list"] count] == 0) {
                
                [MBProgressHUD showtext:@"暂无数据" icon:nil view:nil];
                return;
                
            }
            
            if (self.xuanzhongTag == 0) {
                
                NSArray *renqiArr  = response[@"data"][0][@"list"];
                NSMutableArray *mutabArr = [HWGameListModel mj_objectArrayWithKeyValuesArray:renqiArr];
                
                for (int i = 0; i < mutabArr.count; i++) {
                   
                    [self.sentimentMuArr addObject:mutabArr[i]];
                }
                
    
                self.reQiP = [NSString stringWithFormat:@"%@",response[@"p"]];
                
                // 算出这个这三个数据的高度
                [self yixeilingshi];
              //  [self zuixingshangjian];
             //   [self youxiyugao];
                [self.mainaTableVie reloadData];
               
                
                
            } else if (self.xuanzhongTag == 1) {
                

                NSArray *zuixiArr  = response[@"data"][0][@"list"];
                NSMutableArray *mutabArr = [HWGameListModel mj_objectArrayWithKeyValuesArray:zuixiArr];
                
                for (int i = 0; i < mutabArr.count; i++) {
                    
                    [self.latestMutaBleArr addObject:mutabArr[i]];
                }
                
                self.zuixinP = [NSString stringWithFormat:@"%@",response[@"p"]];
                
                [self zuixingshangjian];
                [self.mainaTableVie reloadData];
                
                
            } else {
                
                
                NSArray *yuGaoArr  = response[@"data"][0][@"list"];
                NSMutableArray *mutabArr = [HWGameListModel mj_objectArrayWithKeyValuesArray:yuGaoArr];
                
                for (int i = 0; i < mutabArr.count; i++) {
                    
                    [self.trailerMutableArr addObject:mutabArr[i]];
                }
                
                self.yugaoP = [NSString stringWithFormat:@"%@",response[@"p"]];
                [self youxiyugao];
                [self.mainaTableVie reloadData];
       
            }
            
            
         
        }
        NSLog(@"%@",response);
        
        
    } failure:^(NSString *error) {
        [self.mainaTableVie.mj_header endRefreshing];
        [self.mainaTableVie.mj_footer endRefreshing];
        
        
    }];
    
    
}


















#pragma  mark ------- 监听通知
- (void)listeningNSNotificationCenter {
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refreshTableView:) name:@"SentimentOnTheSlide" object:nil];
    
    
    
}

- (void)refreshTableView:(NSNotification *)noti {
    
    NSLog(@"%@",noti.userInfo);
    NSDictionary *dic = noti.userInfo;
    NSString *str  = [NSString stringWithFormat:@"%@",dic[@"rolling"]];
    int  a = [str intValue];
    // judgeStr
    NSLog(@"网游");
    
    if ([dic[@"judgeStr"] isEqualToString:@"0"]) {
        self.xuanzhongTag = a;
        [self.mainaTableVie reloadData];
    }

    
    
}



#pragma  mark ------ 监听通知



#pragma  mark ---------- 算出 人气热门  最新上架 新预告 的高度

// 人气热门
- (void)yixeilingshi {

    self.diyigeheight = 0;
    for (int i = 0 ; i <  self.sentimentMuArr.count ; i++) {
      HWGameListModel *model = self.sentimentMuArr[i];
      if ([model.guanggao isEqualToString:@"0"]) {
          self.diyigeheight =   self.diyigeheight + 75;

      } else if ([model.guanggao isEqualToString:@"1"]) {

          self.diyigeheight =   self.diyigeheight + 145;

      } else {

            self.diyigeheight =   self.diyigeheight + 55*CFLScaleValue+10;

        }


    }

}

// 最新上架
-(void)zuixingshangjian {


    self.ergeheight = 0;
    for (int i = 0 ; i <  self.latestMutaBleArr.count ; i++) {
        HWGameListModel *model = self.latestMutaBleArr[i];
        if ([model.guanggao isEqualToString:@"0"]) {
            self.ergeheight =   self.ergeheight + 75;

        } else if ([model.guanggao isEqualToString:@"1"]) {

            self.ergeheight =   self.ergeheight + 145;

        } else {

            self.ergeheight =   self.ergeheight + 55*CFLScaleValue+10;

        }


    }



}


//新游戏预告高度
- (void)youxiyugao {


    self.sangegeheight = 0;
    for (int i = 0 ; i <  self.trailerMutableArr.count ; i++) {
        HWGameListModel *model = self.trailerMutableArr[i];
        
        if ([model.guanggao isEqualToString:@"0"]) {
            self.sangegeheight =   self.sangegeheight + 75;

        } else if ([model.guanggao isEqualToString:@"1"]) {

            self.sangegeheight =   self.sangegeheight + 145;

        } else {

            self.sangegeheight =   self.sangegeheight + 55*CFLScaleValue+10;

        }

    }



}




- (void)networkRequestData {

    [SVProgressHUD show];
    __weak typeof(self) weakSelf = self;
    NSDictionary *parametes = @{
                                @"type" : @"0",
                                @"t" : @"0",
                                @"p" : @"0",
                                @"ios" : @"1",
                                @"ct" :  @"app",
                                @"ac" : @"index"

                                };

    [HWWebUtils doGetWithParameters:parametes progress:nil success:^(id response) {

        [SVProgressHUD dismiss];


        NSString *codeStr =  [NSString stringWithFormat:@"%@",response[@"code"]];

        if ([codeStr intValue] == 1) {
            NSArray *arr  = response[@"banner"];
            self.ADModelMuArr =  [AdModel mj_objectArrayWithKeyValuesArray:arr];

            NSArray *newsArr  = response[@"news"];

            self.xingweMuArr = [HWNewsModel mj_objectArrayWithKeyValuesArray:newsArr];

            NSArray *jingpinArr  = response[@"jingpin"];
            self.jingpinMuArr =  [HWJingPingModel mj_objectArrayWithKeyValuesArray:jingpinArr];


            NSArray *renqiArr  = response[@"data"][0][@"list"];
            self.sentimentMuArr = [HWGameListModel mj_objectArrayWithKeyValuesArray:renqiArr];

            NSArray *latestArr  = response[@"data"][1][@"list"];
            self.latestMutaBleArr  = [HWGameListModel mj_objectArrayWithKeyValuesArray:latestArr];

            NSArray *traileArr = response[@"data"][2][@"list"];
            self.trailerMutableArr  = [HWGameListModel mj_objectArrayWithKeyValuesArray:traileArr];

            // 算出这个这三个数据的高度
            [self yixeilingshi];
            [self zuixingshangjian];
            [self youxiyugao];
            [self refreshData];
        }




        NSLog(@"%@",response);


    } failure:^(NSString *error) {
        [SVProgressHUD dismiss];


    }];



}

- (void)refreshData {


    NSMutableArray *urlArr = [[NSMutableArray alloc]init];
    NSInteger count = self.ADModelMuArr.count;
    for (int i = 0 ; i < count;i++) {
        AdModel *mode =  self.ADModelMuArr[i];
        [urlArr addObject:mode.image];
    }
    self.cycleScrollView.imageURLStringsGroup = urlArr;


    NSMutableArray *xingwenArr = [[NSMutableArray alloc]init];
    NSInteger xingwencount = self.xingweMuArr.count;
    for (int i = 0 ; i < xingwencount;i++) {
        HWNewsModel *mode =  self.xingweMuArr[i];
        [xingwenArr addObject:mode.title];
    }

    if (xingwenArr.count > 0) {
         self.adgugaview.adTitles = xingwenArr;

         [self.adgugaview beginScroll];
    }


    // mobileGameView
    // 精品手游这一块的游戏啊
    self.mobileGameView.modelArr = self.jingpinMuArr;
    [self.mobileGameView roadRefresh];

    // 刷新单元格
    [self.mainaTableVie reloadData];




    // 刷新单元格
//
//    self.renqiOrZuixinview.sentimentMuArr = self.sentimentMuArr;
//    self.renqiOrZuixinview.latestMutaBleArr = self.latestMutaBleArr;
//    self.renqiOrZuixinview.trailerMutableArr = self.trailerMutableArr;
//    self.renqiOrZuixinview.frame = CGRectMake(0, 0, kScreenW, self.diyigeheight);
//
//    [self.renqiOrZuixinview QC_refreshData];





}














- (void)setupAttribute {

    self.xuanzhongTag = 0;
    self.view.backgroundColor = [UIColor redColor];


}

- (void)setupUI {

    [self.view addSubview:self.mainaTableVie];

}

//设置UitabelView 头部
- (void)setupheadeView {


    // LFServiceViewController
    self.headerView  = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, 150+10+35+144+12)];
    self.headerView.backgroundColor = RGB(244, 244, 244);
    self.mainaTableVie.tableHeaderView = self.headerView;

    self.shufflingFigureView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, 150)];
    //self.shufflingFigureView.backgroundColor = RGB(217, 247, 250);
    self.shufflingFigureView.backgroundColor = [UIColor whiteColor];
    
    [self.headerView addSubview:self.shufflingFigureView];



    self.cycleScrollView.localizationImageNamesGroup = @[[UIImage imageNamed:@"banner"],[UIImage imageNamed:@"banner"],[UIImage imageNamed:@"banner"]];
    //轮播图
    //  self.cycleScrollView.imageURLStringsGroup = imagesURLStrings;
    //轮播图
    [self.shufflingFigureView addSubview:_cycleScrollView];

    // homePrompt_icon

    UIView *bejiview = [[UIView alloc]initWithFrame:CGRectMake(10, CGRectGetMaxY(self.cycleScrollView.frame)+5, kScreenW-20, 20)];
    bejiview.backgroundColor = RGB(250, 230, 229);
    
    bejiview.layer.cornerRadius = 5;
    bejiview.layer.masksToBounds = YES;
    [self.shufflingFigureView  addSubview:bejiview];

    UIImageView *hornimage = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 20, 20)];
    hornimage.image = [UIImage imageNamed:@"homePrompt_icon"];
    [bejiview addSubview:hornimage];

//    self.rollingLabel = [[UILabel alloc]initWithFrame:CGRectMake(20+10, 0, kScreenW-20-20-10, 20)];
//    self.rollingLabel.font = [UIFont systemFontOfSize:13];
//    self.rollingLabel.textColor  = RGB(76, 70, 110);
//    self.rollingLabel.text = @"用户186****9642战神280返利";
//    [bejiview addSubview:self.rollingLabel];
    
    


    NSArray *arrayyouxi = @[@"欢迎来到我们游戏平台"];
    HRAdView * gaoview = [[HRAdView alloc]initWithTitles:arrayyouxi];
   // gaoview.backgroundColor = [UIColor redColor];
    gaoview.frame = CGRectMake(0, 0, kScreenW-20-20-10, 20);
    gaoview.textAlignment = NSTextAlignmentLeft;//默认
    gaoview.isHaveHeadImg = YES;
    gaoview.isAutoScroll=YES;
    gaoview.isHaveTouchEvent = YES;
    gaoview.labelFont = [UIFont boldSystemFontOfSize:12];
    gaoview.color = RGB(51, 51, 51);
    gaoview.time = 3.0;
    __weak typeof(self) weakself = self;

    gaoview.clickAdBlock = ^(NSUInteger index){
        //        DetailViewController *vc = [[DetailViewController alloc]init];
        //
        //        vc.text = [NSString stringWithFormat:@"%@",array[index]];
        //        [weakself.navigationController pushViewController:vc animated:YES];
       // NSLog(@"%@",array[index]);

        NSLog(@"打印 %ld",index);
        
        
//        HWNewsModel *mode =  self.xingweMuArr[index];
//        HWGameDetailsViewController *details = [[HWGameDetailsViewController alloc]init];
//        details.gameId = mode.id;
//        [self.navigationController pushViewController:details animated:YES];
        
      HWNewsModel *mode =  self.xingweMuArr[index];
      HWWebViewGameViewController *webview = [[HWWebViewGameViewController alloc]init];
        webview.urlString = [NSString stringWithFormat:@"%@?ct=aznews&ac=info&id=%@&language=%@",[HWOCGlobalConst baseUrl],mode.id,[HWjianzhiduiObject returnLanguageAcquisition]];
        
      webview.gname =mode.title;
      webview.hidesBottomBarWhenPushed = YES;
      [self.navigationController pushViewController:webview animated:YES];
        
        
        
        
        
//        血染征袍兵种克制与搭配？,
//        一周热门资讯：SKT再度捧杯 苹果与腾讯关系紧张 ,
//        一分钟带你了解《超时空战姬》 ,
//        《冒险家》新手全攻略,  // 3
//        《艾德尔冒险》新手急速升级要点,
//        《艾德尔冒险》后期职业搭配攻略,
//        公会副本攻略, //
//        高阶职业介绍,
//        《冒险家初阶职业介绍》,
//        《冒险家》奥术水晶攻略
        
        
        


    };
    [bejiview addSubview:gaoview];

    // 新游
    self.adgugaview = gaoview;
    [self.adgugaview beginScroll];

    // 精品网游
    [self qualityGoodsGame];


}
// 精品网游
- (void)qualityGoodsGame {

    self.qualitygameView = [[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(self.shufflingFigureView.frame)+5, kScreenW, 35+144+12)];
  //  self.qualitygameView.backgroundColor = RGB(217, 247, 250);
    self.qualitygameView.backgroundColor = [UIColor whiteColor];
    
    [self.headerView addSubview:self.qualitygameView];

    UILabel *netLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, kScreenW-20, 35)];
    netLabel.font = [UIFont systemFontOfSize:13];
    netLabel.textColor  = RGB(50, 50, 50);
    netLabel.text = @"精品·手机网游";
    netLabel.font = [UIFont systemFontOfSize:15];
    [self.qualitygameView addSubview:netLabel];

    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(kScreenW-73-10, 6, 73, 23);
    [button setBackgroundImage:[UIImage imageNamed:@"gameHall_dating"] forState:UIControlStateNormal];
    [self.qualitygameView addSubview:button];
    [button addTarget:self action:@selector(buttonTap) forControlEvents:UIControlEventTouchUpInside];
    
    self.mobileGameView = [[HWMobileGameView alloc]initWithFrame:CGRectMake(0, 35, kScreenW, 156)];
 //   self.mobileGameView.backgroundColor = RGB(217, 247, 250);
    self.mobileGameView.backgroundColor  = [UIColor whiteColor];
    [self.qualitygameView addSubview:self.mobileGameView];


}



- (void)buttonTap {
    
    DLog(@"网游 * 游戏大厅");
    FenLeiViewController  *fenlei  = [[FenLeiViewController alloc]init];
    fenlei.judgeStr = @"1";
    [self.navigationController pushViewController:fenlei animated:YES];
    
    
    
}


#pragma  mark ------- 添加Tabview
-(void)addtablviefootView {


  //  UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, kScreenH)];

    UIView *view = [[UIView alloc]init];

    self.mainaTableVie.tableFooterView = view;





//
//    self.renqiOrZuixinview = [[HWRenqiOrZuixinOrYuGaoView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, kScreenH -150-10-156-35 - CF_NavHeight - CF_TabbarHeight-44 + 600)];
//    self.mainaTableVie.tableFooterView = self.renqiOrZuixinview;


}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

    return  1;

}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return  1;


//    if (self.xuanzhongTag == 1 ) {
//
//
//         return self.latestMutaBleArr.count;
//
//
//    } else if (self.xuanzhongTag  == 2) {
//
//        return self.trailerMutableArr.count;
//
//
//
//    } else {
//            return  self.sentimentMuArr.count;
//
//    }
//
//
//    return  self.sentimentMuArr.count;





}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *cellID = @"YouXiID";
    HWYouXiCell  *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
   
    if (!cell) {
        cell = [[HWYouXiCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
    }
    cell.selectionStyle =  UITableViewCellSelectionStyleNone;
    cell.sentimentMuArr = self.sentimentMuArr;
    cell.latestMutaBleArr = self.latestMutaBleArr;
    cell.trailerMutableArr = self.trailerMutableArr;
    cell.diyigeheight = self.diyigeheight;
    cell.ergeheight = self.ergeheight;
    cell.sangegeheight = self.sangegeheight;
    cell.xuanzhongTag = self.xuanzhongTag;
    cell.judgeStr = @"0";
    [cell shuxiangCell];
    return  cell;
    
    
    
    
    
    
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {

   
    if (self.xuanzhongTag == 0) {
        
        if (self.diyigeheight ==  0) {
            return  180;
        }
        
         return  self.diyigeheight;
        
    } else if (self.xuanzhongTag == 1) {
        
        if (self.ergeheight == 0) {
            return  180;
        }
        
        return  self.ergeheight;
        

    } else {
        
        if ( self.sangegeheight  ==   0) {
            
            return  180;

        }
        
        return  self.sangegeheight;
        
    }
    
    

    HWGameListModel *model  = nil;

    if (self.xuanzhongTag == 1 ) {


        model =  self.latestMutaBleArr[indexPath.row];


    } else if (self.xuanzhongTag  == 2) {

        model =  self.trailerMutableArr[indexPath.row];



    } else {
        model = self.sentimentMuArr[indexPath.row];

    }
    

    if ([model.guanggao isEqualToString:@"0"]) {

        return  75;
    } else if ([model.guanggao isEqualToString:@"1"]) {


        return  100 + 10 + 35 ;
    } else {

        return  65;

    }

    return  75;





}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {

     return  35;

}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {

     return  0.01;


}
- (nullable UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {

    if (section == 0) {
        UIView *viewheade = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, 35)];
        viewheade.backgroundColor = [UIColor whiteColor];
        NSArray *array = @[@"人气热门",@"最新上架",@"新游预告"];

        CGFloat jiaju = (kScreenW - 3*80 - 28)/2;
        for (int i = 0; i < array.count; i++) {
            UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
            button.tag = i;

            [button setTitle:array[i] forState:UIControlStateNormal];
            button.frame  = CGRectMake(14+i*80 + i*jiaju , 5, 80, 25);
            button.titleLabel.font  = [UIFont systemFontOfSize:12];
            button.backgroundColor = [UIColor whiteColor];
           // button.titleLabel.textColor = RGB(50, 50, 50);
            [button setTitleColor:RGB(50, 50, 50) forState:UIControlStateNormal];
            [viewheade addSubview:button];
            button.layer.cornerRadius = 6;
                     button.layer.masksToBounds = YES;
                     
            [button addTarget:self action:@selector(selectedTap:) forControlEvents:UIControlEventTouchUpInside];
            [button setBackgroundImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];


            if (i == self.xuanzhongTag) {
                [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
               //  [button setBackgroundImage:[UIImage imageNamed:@"QCxuanzhong"] forState:UIControlStateNormal];
                 button.backgroundColor =  QCchunseshensetupian;
                self.xuanzhongBut = button;
            }

        }

        return viewheade;

    } else {
         UIView *viewheade = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, 65)];
         viewheade.backgroundColor = [UIColor whiteColor];


        NSArray *array = @[@"youxiang_dating",@"kaifubia",@"home_QCb3"];
        CGFloat jiajue  = (kScreenW - 110 * 3-28)/2;
        for (int i = 0; i < array.count; i++) {

            UIImageView *imaview = [[UIImageView alloc]initWithFrame:CGRectMake(110*i+jiajue*i+14, 5, 110, 55)];
            imaview.image = [UIImage imageNamed:array[i]];
            [viewheade addSubview:imaview];

        }

        return viewheade;
    }





}


//- (nullable UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
//
//    UIView *footerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, 0.01)];
//    footerView.backgroundColor = [UIColor whiteColor];
//    return footerView;
//
//}


#pragma mark ----- 点击选中按钮
- (void)selectedTap:(UIButton *)sender {

    [self.xuanzhongBut setTitleColor:RGB(50, 50, 50) forState:UIControlStateNormal];
    [self.xuanzhongBut setBackgroundImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];

    [sender setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
   //  [sender setBackgroundImage:[UIImage imageNamed:@"QCxuanzhong"] forState:UIControlStateNormal];
    
    
    sender.backgroundColor =  QCchunseshensetupian; 
    self.xuanzhongBut = sender;

    self.xuanzhongTag = (int)sender.tag;

    [self.mainaTableVie reloadData];




}







#pragma mark --------------- 轮播图代理

- (void)cycleScrollView:(SDCycleScrollViewCdb *)cycleScrollView didSelectItemAtIndex:(NSInteger)index {
    
    
    if (self.ADModelMuArr.count > 0) {
        
           AdModel *model =   self.ADModelMuArr[index];
          HWGameDetailController *gameDetails = [[HWGameDetailController alloc]init];
          gameDetails.gameId = model.gid;
          [self.navigationController pushViewController:gameDetails animated:YES];
        
        
        return;
        
    }
    
    
    
}


-(void)dealloc {
    
    [[NSNotificationCenter defaultCenter]removeObserver:self];
    
}

@end







